home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
015a
/
stuf12.zip
/
BATSTUFF.DOC
< prev
next >
Wrap
Text File
|
1991-09-13
|
38KB
|
916 lines
STEENBURGH'S STUFF
Mildly Useful Utilities
For Batch Files
Version 1.2
Copyright 1991 by Chuck Steenburgh
Practically everyone who owns a PC has written a batch
file at one time or another. Batch files can give even the
novice user powerful tools to manage and control his or her
computer. While the capabilities of batch files have slow-
ly improved through successive releases of MS-DOS, there
are real limits on what you are capable of with batch files.
Some of the biggest complaints about batch files:
- Lack of interactive features
- Poor screen/speaker output capabilities
- SLOW!
- Inability to to access certain types of system info
Over the years, many batch file "compiler" languages
have appeared on the scene. Interested in greater speed
and power for my batch files, I evaluated several of the
shareware versions of these utilities. Unfortunately,
they only seemed to be as hard (if not harder) than learn-
ing a completely new programming language. More often
than not, these systems wouldn't even compile "plain"
batch files that I was using without any special commands!
Having struck out with the batch file compilers, I
then started collecting miscellaneous utilities to try
to expand my batch file capability piecemeal. While there
are many excellent programs available, they generally
have drawbacks of one kind or another. Some programs are
tiny (less than 1K) .COM files that are speedy but don't
do enough and have very limited options. There are other
programs that are more capable, but bigger and slower and
usually involving several zillion command line switches to
get anything useful out of the program.
Frustrated, I decided to start writing my own set of
utilities. Over several month's time, these utilities de-
veloped into the collection I call "STEENBURGH'S STUFF:
Mildly Useful Utilities." These programs are listed below:
BATBOX: Simple menu creation/input system
FREEDISK: Checks for available disk space
INPUT: Simple prompt/input system
KLS: Colorful screen-clearing utility
LAUNCHER: File selection/execution system
MUSIC11: Plays transcribed sheet music on the PC
Page 1
RAND: Random number generator
SKIP: Prints blank lines from batch files
SOUNDER: Wide range of noise making options
WAITFOR: Timed pauses
WHENISIT: Date/time telling utility
WRITE: Colorful output anywhere on screen
XD: Create/switch directories at the same time
As much as possible, I have tried to compromise between
program size on the one hand (keeping them small and fast)
and features on the other. As you will see, most of the
programs are under 10K, and none is over 20K. While this
is considerably larger than some assembly language programs
(I have a program that prints individual blank lines from
batch files that is only 12 bytes!), the entire collection
takes up less than 100K of disk space. This is less than
just the documentation for some larger utilities!
The size of these programs is due to their being compiled
in 'C'. However, these programs are FAST, for several rea-
sons. First, they were compiled with the Power C compiler
from Mix Software. Power C may not be the most capable of
compilers, but it is probably the fastest DOS compiler around
overall. (Folks who spend $495 on Microsoft C don't want to
believe that a $20 compiler is faster, but it is). Second,
these programs leave out some of the "cute" features that
other programs include that slow them down considerably. For
example, when you run "MUSIC11" you'll hear sounds all right,
but no animated cherubs will perform aerobatics while the
music plays. When you run FREEDISK, you will not see an
aquarium filled with swimming fish representing the number
of occupied bytes of disk space. You will get concise, neat
information on the screen, in most cases accompanied by an
errorlevel which can be evaluated intelligently.
INDIVIDUAL PROGRAM DESCRIPTIONS
========== ======= ============
BATBOX.EXE
People have been creating menus with batch files for
years. Some of these are quite elaborate, others very crude.
BATBOX is something in between. BATBOX will allow you to
display an attractive, colorful menu and will wait for
the user to make a selection. It will then set an appro-
priate ERRORLEVEL value which can be used to determine sub-
sequent actions in your batch file.
Usage: BATBOX menufile
menufile is the name of an ASCII text
file which you create. This
will contain the menu's title
Page 2
and a list of options.
To create a menufile, use a text editor, word processor
that can save ASCII files, or EDLIN.COM or EDIT.COM that
come with DOS. In a pinch, you can use the "copy con" com-
mand but this doesn't give you much in the way of an editing
capability.
The structure of the menufile is simple. The first line
contains your menu's title, up to 20 characters. If you
don't want a title, leave the line blank, without any spaces.
(Hint: press RETURN immediately without doing anything else
when you first begin editing your document.) Each succes-
sive line contains a menu item, exactly as you want it to ap-
pear on the screen. Do NOT include any blank lines here or
you will end up with blank lines in your menu!
A few limitations: each line can contain no more than 60
characters (if you need more than this to describe your menu
choices, maybe you need Microsoft Windows, a Macintosh, or
something else with lots of pictures). In addition, your menu
items (but NOT the menu title) must each begin with a dis-
tinct letter in order for the selection function to work pro-
perly. The selection function for BATBOX is case-insensitive,
so if you begin one line with the letter 's' and the other
with the letter 'S', these are considered the same. Up to
10 menu items are permitted in any one file. Finally, make
sure you include a space after the last letter of the last
menu item, but do NOT press return. Save the file from that
point.
When you type BATBOX on the command line followed by the
name of your menufile (they must both be in the current dir-
ectory), you will see a menu pop up in the middle of the
screen. The title will appear at the top, with each of your
menu items (up to ten) appearing at double spaced-intervals
inside the menu box. At the bottom of the menu you will see
a the message "Enter your menu choice: ". If you have a
color monitor, you will notice that the first letter of each
menu item appears in a different color than the rest of the
text.
Selecting a menu item is as simple as pressing the first
letter in the name of that item (the letter that is displayed
in a different color). BATBOX will then exit, and return an
errorlevel based on the key that was pressed. See Appendix
1 for a list of legal first letters and the errorlevels that
are returned by BATBOX. You can use the errorlevel value
that is returned to branch to different parts of your batch
file or to execute commands. See the DEMO.BAT file for an
example of one way to do this.
FREEDISK.EXE
Page 3
Ever started a program only to find out that your disk
did not have enough room to store any data? Want to have
your batch files tell you when it is time to swap disks or
clean up your hard drive? FREEDISK to the rescue! FREEDISK
can be used from the command line as a quick way to deter-
mine your remaining disk space (much faster than using the
DOS commands like dir or chkdsk). FREEDISK really shines,
however, in batch files, where it can help your batch file
programs make decisions based on remaining disk space.
Usage: FREEDISK [drive] [space needed]
drive a single letter representing
the disk drive you want to
check. You don't need a colon,
and the default is the current
disk drive. [optional]
space needed the number of kilobytes of free
disk space you feel is necessary
in order to continue. A kilo-
byte is 1,024 bytes (binary pur-
ist that I am!). [optional]
Examples:
FREEDISK displays the total and available
space on the current dirve. Also
returns available space as error-
level (see below).
FREEDISK b displays the total and available
space on drive B.
FREEDISK 10000 displays the total and available
space on the current drive. If
the available space is less than
10,000 kilobytes, FREEDISK will
sound an alarm and set the error-
level.
FREEDISK displays available and total space in megabytes.
Since a megabyte is 1,024 kilobytes or 1,048,576 bytes, the
numbers shown might look a little different than what the
guy who sold you your disk drive said. That's OK, salesmen
tend to define a "K" as 1,000 so they can make their products
look better. It's all the same, you're not losing any bytes
one way or another. My salesman, for example said my Seagate
ST-251 had 42 megabytes; FREEDISK reports it at only 40.6 meg.
FREEDISK will return one of four possible errorlevels:
0 Normal termination, sufficient disk space available
Page 4
1 Error reading available disk space
2 Not enough space available
When the no needed space is indicated on the command line,
FREEDISK will set the errorlevel equal to the amount of space
available on the drive, in 10K increments. For example, if
you specify "FREEDISK A" on the command line, and drive A has
240K of free space left, FREEDISK will return an errorlevel of
24. If there are more than 2.55 megabytes available, the
errorlevel will be set to 255. This feature is useful when
you want your batch file to selectively delete files on the
target until a certain amount of space remains (for example).
INPUT.EXE
If you use batch files very often, you've probably acquired
a program called ASK.COM or QUERY.COM or something similar
that allows you to ask questions and receive simple respones.
Usually, this involves typing an ECHO command with your
question, followed by ASK.COM or whatever. If you do this
alot, you will probably appreciate the fact the INPUT.EXE
will accomplish the jobs of both the ECHO and ASK commands.
Add to this the greater flexibility that INPUT.EXE offers
in presenting your prompt to the user and in receiving input,
and you'll be sold.
Usage: INPUT ["prompt"] [color] [/c]
"prompt" Enter the text you would like to
appear to prompt the user for
input. This can be up to 59 char-
acters and must be enclosed in
quotation marks.
color Enter a number representing the
color in which you want your mes-
sage to appear. You must, of
course, have a color monitor and
card. See Appendix 3.
/c Include this switch if you want
your prompt message centered on
the current line. If you include
this switch, you MUST include a
color value.
Examples:
INPUT "Select a number from one to 10"
This prints the text "Select on number from one to 10"
on the current line and waits for a keypress.
Page 5
INPUT "Press any key to continue" 79
This prints the text "Press any key to continue" on the
current line in bright white on a red background and waits
for a keypress.
INPUT "Press the space bar to exit" 143 /c
This prints the text "Press the space bar to exit" cen-
tered on the current line in flashing bright white on a black
background.
INPUT will also sound an alarm to let the user know that
a response is expected.
When a key is pressed, INPUT will set the errorlevel equal
to the ASCII value of the key pressed. This is slightly dif-
ferent from BATBOX in that INPUT is case sensitive and will
allow you to distinguish between upper and lower case letters.
See Appendix 2 for a complete list of the ASCII characters
theoretically supported by INPUT.
KLS.EXE
KLS is a simple replacement for the DOS screen-clearing
function (CLS).
Usage: KLS [color]
color A number from the list below:
0 - Black
1 - Blue
2 - Green
3 - Cyan
4 - Red
5 - Magenta
6 - Brown
7 - White
Examples:
KLS 4 Clears the screen & paints it red.
KLS 6 Clears the screen & paints it brown.
When the screen is cleared, it will be set to the color indi-
cated on the command line. Entering KLS without parameters
is the same as issuing CLS (i.e., clear screen without color).
"KLS 0" is useful if you have used ANSI or some other method
to set your screen to a color other than black, but you want
a black screen temporarily.
Page 6
KLS returns errorlevel codes as shown below:
0 - Normal execution (color specified)
1 - Normal execution (no color specified)
2 - Error (did not execute)
LAUNCHER.EXE
Do some of your programs require you to load a data file
once you start the program? Are these data files located on
a crowded disk, or do you have to enter several cryptic com-
mands to get your program to load a data file? LAUNCHER is
designed to work with any program that can accept the name of
a data file on the command line. LAUNCHER will display a
menu of your data files, and then start your application with
the name of the file you select on the command line to be
loaded immediately.
LAUNCHER uses a rather novel method of automatically de-
termining the name of the application you are going to use
it with. Rather than needing a configuration file or compli-
cated command line switches, LAUNCHER reads the application
name from its own file name. Rename the LAUNCHER.EXE file
after the application you want to run, PLUS ANY ONE ADDITIONAL
CHARACTER. Put this renamed version of launcher in the same
directory as your application, and you're ready to LAUNCH!
Usage: NEWNAME [[path:\]filespec] [/f]
NEWNAME This is the new name which you have
given to LAUNCHER.EXE, based on the
name of your application.
path:\ Optional drive and/or path for data
files.
filespec This filespec designates what files
are to be displayed by LAUNCHER.
You may include a drive and/or dir-
ectory name, and wildcards (? *).
/f Include only file names on command
line. Normally, LAUNCHER will in-
clude any path you have specified
on the command line string built.
Use this switch if your application
does not require the path name.
Examples:
WPI b:\wp\*.doc This will LAUNCH Word Perfect
(WP.EXE) after displaying all files
in the B:\WP subdirectory with the
Page 7
extension .DOC. This assumes that
you have renamed LAUNCHER.EXE as
WPI.EXE and that this file is in the
same directory as Word Perfect.
1234 c:\*.w?? This will LAUNCH Lotus 1-2-3
(123.BAT) after displaying all
worksheet files in the root direc-
tory of drive C. This assumes that
you have renamed LAUNCHER.EXE as
1234.EXE and that this file is in
the same directory as 1-2-3.
WSI c:\ws\docs\*.doc LAUNCHES WordStar (WS.EXE) from
data files in directory c:\ws\docs.
DOES NOT include the path when
LAUNCHING WordStar.
For some inexplicable reason, Quattro Pro Version 3.0 does
not work correctly (i.e., locks up) after being LAUNCHED. I
am trying to get Borland's Techincal Support folks to help me
figure out why, but until then, you probably shouldn't use
Quattro Pro 3.0 with LAUNCHER.EXE.
MUSIC11.EXE
For some time now I have wanted an inexpensive way to
play short tunes on my PC. While there are many music pro-
grams available, they usually require expensive hardware,
large memory overhead, too much musical knowledge, or custom-
made musical files that you had to buy from somebody. Des-
perate, I finally decided to write my own program!
Usage: MUSIC11 file[.CM1]
file The name of a music file with
extension .CM1 which contains
the transcribed music to be
played. Extension is optional.
Examples:
MUSIC11 dixie2.cm1 Plays the song "Dixie" encoded
in the file DIXIE2.CM1 (this
file included with the STUFF).
MUSIC11 returns errorlevel values as shown below:
0 Normal termination
1 Invalid music file
2 Note improperly coded
For information on how to create your own music files, see
Page 8
Appendix 4 and use the sample files as a guide.
RAND.EXE
RAND provides simple random number generating capabilities
for batch files. RAND returns a random number in the form of
the DOS errorlevel, which you can then evaluate in your batch
files.
Usage: RAND [max value]
max value Upper limit of random number range.
RAND will generate an errorlevel
between 1 and this number. The de-
fault is 100. The maximum is 255.
Examples:
RAND Generates a random errorlevel be-
tween 1-100.
RAND 10 Generates a random errorlevel be-
tween 1-10.
If the max value specified is greater than 255 or less than
1, RAND sets the errorlevel to 0.
SKIP.EXE
ECHO does not permit you to enter blank lines in batch
files. While there are various tricks to accomplish this,
and a number of small .COM programs to accomplish this task,
you must still enter a separate command for each blank line.
Usage: SKIP [lines]
lines The number of lines you would like
to skip; the default is one.
Examples:
SKIP Skips a sinlge line
SKIP 5 Skips five lines.
SKIP sets the errorlevel equal to the number of lines skipped.
SOUNDER.EXE
SOUNDER is an advanced replacement for any number of util-
ities (with names like BEEP.COM or MUSIC.COM). Most of these
Page 9
programs make a simple noise or maybe play a short melody.
Most restrcit you to the same monotnous tones over and over
again. SOUNDER not only presents you with a virtually unlim-
ited range of options which you can control, it will also gen-
erate over a 1,000 random tone combinations for you if you are
feeling indecisive, or play one of four random melodies.
Usage: SOUNDER [freq dur] | [note dur] | [m]
freq A frequency in cycles per second
(Hz) of the tone you desire. Valid
values are 19 to 15,000 Hz.
note A musical note (A,B,C,D,E,F,G).
dur Duration of tone or note in clock
ticks. There are roughly 18.2
ticks per second. Must be a whole
number between 1 and 100.
m Indicates that SOUNDER should play
a few notes from one of four random
melodies encoded in the program.
Entering SOUNDER without parameters
will cause it to produce from 1-3
random noises for a total length of
approximately 2/3 second.
Examples:
SOUNDER Produces 1-3 random noises.
SOUNDER 1000 18 Produces a 1,000 Hz tone for one
second.
SOUNDER C 36 Produces a 'C' note for two
seconds.
SOUNDER m Plays one of four random tunes.
SOUNDER returns the following errorlevel codes:
0 Tone or musical note properly sounded
1-3 Number of random noises generated
4 Random melody played
5 Invalid parameter (only one supplied)
6 Invalid parameter(s) (tone, frequency, and/or
duration outside of allowable range)
WAITFOR.EXE
Did you ever notice that if you want a batch file to wait
Page 10
for you, you have to use PAUSE? This requires you to press
a key. This may not be convenient at the moment, such as
when you're talking on two phones at once and your batch file
is patiently waiting for you to tell it to print those files
your boss is imnpatient for. WAITFOR will simply cause your
batch file to cease operation for a designated number of sec-
onds and then resume.
Usage: WAITFOR seconds
seconds Integer representing the number
of seconds you would like to
pause.
WAITFOR sets the errorlevel equal to the number of seconds
paused.
WHENISIT.EXE
WHENISIT is a highly flexible utility to provide control in
DOS batch files based on time and date. With its many op-
tions, WHENISIT will allow your batch files to determine the
year, month, date, day of the week, hour, minute, second, or
whether it is morning or afternoon and make intelligent de-
cisions based on this information.
For example, you may want certain actions performed at
boot time on certain days of the week or month. Adding
WHENISIT to your AUTOEXEC.BAT file can allow you to make
these sort of decisons. (Or allow your computer to make them
for you automatically.)
Usage:
WHENISIT [/a]|[/d]|[/h]|[/m]|[mi]|[/s]|[/w]|[/y]
/a Returns errorlevel based on am or pm
/d Returns errorlevel equal to date
/h Returns errorlevel equal to the hour
(24-hour clock)
/m Returns errorlevel equal to month
/mi Returns errorlevel equal to minute
/s Returns errorlevel equal to second
/w Returns errorlevel based on the day
of the week
/y Returns errorlevel equal to the last
Page 11
two digits of the year.
Examples:
WHENISIT /a Returns errorlevel of 2 if it is pm,
or 1 if it is am.
WHENISIT /y If your clock is set to the year
1991, returns an errorlevel of 91.
WHENISIT /w If your clock indicates that it is
Tuesday, returns an errorlevel of 3.
Errorlevel Chart:
Errorlevel Switch: /a /m /d
---------- --------------------------------------
1 AM January Sunday
2 PM February Monday
3 na March Tuesday
4 na April Wednesday
5 na May Thursday
6 na June Friday
7 na July Saturday
8 na August na
9 na September na
10 na October na
11 na November na
12 na December na
The errorlevels returned through the use of other switches
should be self-explanatory. If an error occurs, the an error-
level of 0 will be returned.
Entering WHENISIT alone on the command line will present a
summary of the command line options for WHENISIT.
WRITE.EXE
We know that ECHO has its limits, don't we? WRITE will let
you have full control over the positioning and color of your
text messages in batch files.
Usage: WRITE "message" row [color] | [column] [color]
"message" This is the text to be displayed,
which must be enclosed in quotes.
row This is the row (0-24, top to bot-
tom) on which the text will appear.
[column] This is the optional column (0-79,
left to right) where the text will
Page 12
begin printing. The default is to
center the text on the row. If this
is included, you must also include
a color value (or else this will be
interpreted as a color).
[color] This is the optional color in which
to print the text. See Appendix 3.
Examples:
WRITE "Hello" 0 0 15 Prints "Hello" in the top left cor-
ner of the screen, white on black.
WRITE "Hello" 5 Centers "Hello" on line 5.
WRITE "Hello" 10 79 Prints "Hello" centered on line 10
in bright white on a red background.
WRITE returns errorlevels as follows:
0 Normal termination
1 Row/Column values outside of allowable range
2 Color value outside of allowable range
XD.EXE
XD is included as a directory creation/changing utility.
There are better ones available, I suggest you get one if
you can. XD does offer advantages over the cd and md commands
found in DOS.
Usage: XD [drive:][\directory]...
drive: Drive letter (with colon) that you
want to switch to.
\directory Directory (with slash) that you want
to change to. If it does not exist,
XD will create it and then move you
there.
Examples:
XD D:\DOS Changes to drive D: (if necessary)
then changes to the \DOS directory,
creating it if necessary.
XD QPRO\DATA Changes to subdirectory QPRO, then
to subdirectory DATA, creating it
if necessary.
If you are using XD to create a new directory, you may only
Page 13
create one new level. For example, if you issue the command
"XD C:\DOS\UTILITY" and that directory does not exist, XD will
create IF C:\DOS already exists.
XD sets the errorlevel to 1 if the above condition is en-
countered and it is unable to create a new directory.
DISCLAIMER
The programs described in this documentation are guaran-
teed to absolutely nothing! They have, however, in my exper-
ience performed essentially as described herein. The author
will not be responsible for any loss or damages caused through
the use of these programs.
All trademarks are property of their respective owners.
The programs and documentation are Copyright 1991 by Chuck
Steenburgh. You are encouraged to distribute these programs
provided the following conditions are met:
- all files listed in the file FILES.TXT must be distrib-
uted together in UNMODIFIED form
- you charge no more than a reasonable fee for copying or
subscription, and clearly indicate that payment of such
a fee does NOT grant ownership of the programs.
You may evaluate these programs for up to 30 days on a free
trial basis. After 30 days, you should register your use of
these programs. The registration fee is $10, payable to the
author at the address given below.
Let's be real: I don't plan to make alot of money this way.
Registration does have its advantages:
- I am improving these programs all the time. Registration
will get you IMMEDIATELY a disk with the latest version,
which includes a version of BATBOX with user-selected
menu colors. When Version 2.0 of these utilities is re-
leased, you will also receive that free of charge.
- While I can't promise to include everyone's suggestions
in program updates, you can bet I'll listen to registered
users before any of you scrounges out there.
- You will me feel all warm and fuzzy and appreciated, and
all that good stuff.
- You will also get an evaluation copy of my text-file for-
matting program (used to produce the margins in this doc-
ument).
Page 14
Send comments/registrations to:
Chuck Steenburgh
304A North Main Street
Lexington, VA 24450
(703)464-5290
CIS 72330,1776 (I haunt the IBMSYS and IBMPRO forums)
Page 15